package com.xingda.packing.rule.choose;

import com.xingda.packing.domain.ProductBox;
import com.xingda.packing.domain.Wheel;
import com.xingda.packing.enums.BoxTaskType;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

@Order(8)
@Component
@Slf4j
public class CustomerChoose implements ChooseService {
    @Override
    public boolean canChoose(ProductBox productBox, Wheel wheel) {
        boolean result = can(productBox, wheel);
        if (!result) {
            log.info("box:{}, 工字轮条码：{}，客户装箱->{}", productBox.getBoxNo(), wheel.getBarCode(),false);
        }
        return result;
    }

    public boolean can(ProductBox productBox, Wheel wheel) {
        if (productBox.getType() == BoxTaskType.PACKING_CLEAN.getTypeId()) {
            return true;
        }
        if (productBox.getType() == BoxTaskType.PACKING_SEMI_FINISHED_DISQUALITY.getTypeId()) {
            return true;
        }
        if (!productBox.isCustomer()) {
            return true;
        }
        return wheel.getConsumerName().equals(productBox.getConsumerName());
    }
}
